// JavaScript Document
$(function(){
	
  //------------折叠菜单--------------//
	var ele = "#J_nav .navItem-lv1"
	var sib = "#J_nav .subNavBox"
	$(ele).click(function(){
	var $self = $(this);
	var $icon = $(this).find("i");
	var $ul = $self.next(sib);
	var hasSubnav = $ul.length > 0 ? true : false;
		if(hasSubnav){
			if( $ul.is(":visible")){
				$ul.slideUp();
				$icon.removeClass().addClass("icon-show");
				$self.find("a").removeClass();
			}else{
				$ul.slideDown();
				$icon.removeClass().addClass("icon-hide");
				$self.find("a").addClass("current");
			}
		}
		else{
			$self.find("a").toggleClass("current");
			//$icon.removeClass();
		}
		//return false;
		
})
//------------部门结构树折叠菜单--------------//
	var ele1 = "#J_tree .treeItem-lv1"
	var sib1 = "#J_tree .treeNavBox"
	$(ele1).click(function(){
	var $self1 = $(this);
	var $icon1 = $(this).find("i");
	var $ul1 = $self1.next(sib1);
	var hasSubnav1 = $ul1.length > 0 ? true : false;
		if(hasSubnav1){
			if( $ul1.is(":visible")){
				$ul1.slideUp();
				$icon1.removeClass().addClass("icon-show1");
				$self1.find("a").removeClass();
			}else{
				$ul1.slideDown();
				$icon1.removeClass().addClass("icon-hide1");
				$self1.find("a").addClass("current");
			}
		}
		else{
			$self1.find("a").toggleClass("current");
			//$icon.removeClass();
		}
		//return false;
		
})
 //------------部门结构树折叠菜单2--------------//
	var ele2 = "#J_tree .treeItem-a"
	var sib2 = "#J_tree .treeNavBox1"
	$(ele2).click(function(){
	var $self2 = $(this);
	var $icon2 = $(this).find("i");
	var $ul2 = $self2.next(sib2);
	var hasSubnav2 = $ul2.length > 0 ? true : false;
		if(hasSubnav2){
			if( $ul2.is(":visible")){
				$ul2.slideUp();
				$icon2.removeClass().addClass("icon-show1");
				$self2.find("a").removeClass();
			}else{
				$ul2.slideDown();
				$icon2.removeClass().addClass("icon-hide1");
				$self2.find("a").addClass("current");
			}
		}
		else{
			$self2.find("a").toggleClass("current");
			//$icon.removeClass();
		}
		//return false;
		
})

//------------设置权限树折叠菜单--------------//
	var ele3 = "#J_set .setItem-lv1"
	var sib3 = "#J_set .setNavBox"
	$(ele3).click(function(){
	var $self3 = $(this);
	var $icon3 = $(this).find("i");
	var $ul3 = $self3.next(sib3);
	var hasSubnav3 = $ul3.length > 0 ? true : false;
		if(hasSubnav3){
			if( $ul3.is(":visible")){
				$ul3.slideUp();
				$icon3.removeClass().addClass("icon-Ncheck");
				$self3.find("a").removeClass();
			}else{
				$ul3.slideDown();
				$icon3.removeClass().addClass("icon-check");
				$self3.find("a").addClass("current");
			}
		}
		else{
			$self3.find("a").toggleClass("current");
			//$icon.removeClass();
		}
		//return false;
		
})

//------------设置权限树折叠菜单2--------------//
	var ele4 = "#J_set .setItem-a"
	var sib4 = "#J_set .setNavBox1"
	$(ele4).click(function(){
	var $self4 = $(this);
	var $icon4 = $(this).find("i");
	var $ul4 = $self4.next(sib4);
	var hasSubnav4 = $ul4.length > 0 ? true : false;
		if(hasSubnav4){
			if( $ul4.is(":visible")){
				$ul4.slideUp();
				$icon4.removeClass().addClass("icon-Ncheck");
				$self4.find("a").removeClass();
			}else{
				$ul4.slideDown();
				$icon4.removeClass().addClass("icon-check");
				$self4.find("a").addClass("current");
			}
		}
		else{
			$self4.find("a").toggleClass("current");
			//$icon.removeClass();
		}
		//return false;
		
})

//------------设置用户树折叠菜单--------------//
	var ele5 = "#J_set1 .setItem-lv1"
	var sib5 = "#J_set1 .setNavBox"
	$(ele5).click(function(){
	var $self5 = $(this);
	var $icon5 = $(this).find("i");
	var $ul5 = $self5.next(sib5);
	var hasSubnav5 = $ul5.length > 0 ? true : false;
		if(hasSubnav5){
			if( $ul5.is(":visible")){
				$ul5.slideUp();
				$icon5.removeClass().addClass("icon-show1");
				$self5.find("a").removeClass();
			}else{
				$ul5.slideDown();
				$icon5.removeClass().addClass("icon-hide1");
				$self5.find("a").addClass("current");
			}
		}
		else{
			$self5.find("a").toggleClass("current");
			//$icon.removeClass();
		}
		//return false;
		
})
//-------------------------------//
// 左边栏收缩
//-------------------------------//	
var asideBtn = "#J_asideBtn";
var sideWidth = 200;
$(asideBtn).toggle(
	function(){
		$("#J_nav").hide();
		$("#J_aside").width(10);
		$("#J_wrapper .main").css("padding-left",10);
		$("#J_asideBtnIcon").removeClass("arrow-left").addClass("arrow-right");
	},
	function(){
		$("#J_nav").show();
		$("#J_aside").width(sideWidth);
		$("#J_wrapper .main").css("padding-left", sideWidth);
		$("#J_asideBtnIcon").removeClass("arrow-right").addClass("arrow-left");
	});


	
  resetAside();
  /*******/
  //resizeWindow();
  $(window).bind("resize", resizeWindow);
  function resizeWindow(e){
  //-------初始左边栏与右边栏等高---------//	
  resetAside();
  }

  function resetAside(){
	  var aside = "#J_aside";
	  var wrapper = "#J_wrapper";
	  var asideBtn = "#J_asideBtn";
	  $(aside).css({"height":"auto"}); //重设高度
	  $(aside).css({"height":$(wrapper).height()}); //设定左右栏高度一直占满主体部分
	  $(asideBtn).css({"height":$(wrapper).height()});
  }


//-------------------------------//
// 菜单下拉
//-------------------------------//	
	elementHover(".menu-box",null,"menuHover");//加载主菜单js
	elementHover(".menu-box .menu-item",null,"submenuHover");
	elementHover(".person-email",null,"personinfoHover");
		
	function elementHover(ele,eleShow,hover){
	$(ele).hover(
		function(){
			$(this).addClass(hover);
			$(eleShow).fadeIn("slow");
		},
		function(){
			$(this).removeClass(hover);
			$(eleShow).fadeOut("slow");
		}
	);
}


//表单切换相关
//Tabs 注：切换的公共js
function tabs(obj,tabNav,tabCon,tabEvent){
	var index = 0;
	if(tabEvent === true){	
		$(tabNav).mouseover(function(){
			index = $(tabNav).index(this);
			tabsFun(index,tabNav,tabCon);
			tabsFun2(obj,index,tabNav,tabCon);
		 })
	 }else{
		 $(tabNav).click(function(){
			index = $(tabNav).index(this);
			tabsFun(index,tabNav,tabCon);
		 })
		 }
}
function tabsFun(index,tabNav,tabCon){
	$(tabNav).removeClass("current").eq(index).addClass("current");
	$(tabCon).removeClass("current").eq(index).addClass("current");
	}
tabs("#J_tabs-box","#J_tabs-box .tabs-nav li","#J_tabs-box .tabs-con",false);//加载表单切换js
})
	